package demo.practice.double_pointer;

public class P11 {

    public static void main(String[] args) {
        P11 p11= new P11();
        p11.maxArea(new int[]{
                1,8,6,2,5,4,8,3,7
        });
    }
    public int maxArea(int[] height) {
        if (height == null || height.length < 2) {
            return 0;
        }

        //双指针
        int l = 0;
        int r = height.length - 1;
        int maxArea = 0;

        while (l < r) {
            maxArea = Math.max(maxArea, (r - l) * Math.min(height[r], height[l]));
            if (height[l] > height[r]) {
                //
                r--;
            }else {
                l++;
            }
        }

        return maxArea;
    }
}
